package overlay;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import org.osmdroid.ResourceProxy;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.OverlayItem;
import java.util.List;

public class ZoomedItemizedIconOverlay<Item extends OverlayItem> extends ItemizedIconOverlay<Item> {
    public void draw (final Canvas canvas, final MapView mapView, final boolean shadow) {
        if (shadow) return;
        MapView.Projection mapViewProjection = mapView.getProjection();
        for (Item item:this.mItemList) {
            Point point = new Point();
            mapViewProjection.toMapPixels(item.mGeoPoint, point);
            Drawable marker = item.getMarker(0);
            int widthMarker = marker.getIntrinsicWidth();
            int heightMarker = marker.getIntrinsicHeight();
            int pix = (int) Math.floor(mapViewProjection.metersToEquatorPixels(100));
            if (widthMarker > heightMarker) {
                heightMarker = pix * heightMarker / widthMarker;
                widthMarker = pix;
            }
            else {
                widthMarker = pix * widthMarker / heightMarker;
                heightMarker = pix;
            }
            Rect rect = new Rect();
            rect.set(point.x - widthMarker / 2, point.y - heightMarker / 2, point.x + widthMarker / 2, point.y + heightMarker / 2);
            marker.setBounds(rect);
            marker.draw(canvas);
        }
    }

    public ZoomedItemizedIconOverlay(List<Item> pList, Drawable pDefaultMarker, OnItemGestureListener<Item> pOnItemGestureListener, ResourceProxy pResourceProxy) {
        super(pList, pDefaultMarker, pOnItemGestureListener, pResourceProxy);
    }

    public ZoomedItemizedIconOverlay(List<Item> pList, OnItemGestureListener<Item> pOnItemGestureListener, ResourceProxy pResourceProxy) {
        super(pList, pOnItemGestureListener, pResourceProxy);
    }

    public ZoomedItemizedIconOverlay(Context pContext, List<Item> pList, OnItemGestureListener<Item> pOnItemGestureListener) {
        super(pContext, pList, pOnItemGestureListener);
    }
}
